﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.commands {
    import flash.events.*;
    import flash.display.*;
    import reprise.data.*;

    public class MovieClipController extends AbstractAsynchronousCommand {

        protected var m_frameDelayCount:int;// = 0
        protected var m_resetOnExecute:Boolean;// = false
        protected var m_frameRange:Range;
        protected var m_target:MovieClip;
        protected var m_frameDelay:int = 1
        protected var m_direction:int = 1

        public static const DIRECTION_BACKWARDS:int = 2;
        public static const DIRECTION_FORWARDS:int = 1;

        public function MovieClipController(_arg1:MovieClip){
            setTarget(_arg1);
        }
        public function gotoAndPlay(_arg1:int):void{
            _arg1 = normalizedFrame(_arg1);
            m_target.gotoAndStop(_arg1);
            execute();
        }
        public function totalFrames():int{
            return (m_target.totalFrames);
        }
        public function enterFrame(_arg1:Event):void{
            if (++m_frameDelayCount < m_frameDelay){
                return;
            };
            m_frameDelayCount = 0;
            if (m_direction == DIRECTION_FORWARDS){
                if (currentFrame() < ((m_frameRange.location + m_frameRange.length) - 1)){
                    m_target.nextFrame();
                    return;
                };
                notifyComplete(true);
            } else {
                if (currentFrame() > m_frameRange.location){
                    m_target.prevFrame();
                    return;
                };
                notifyComplete(true);
            };
        }
        public function setFrameRange(_arg1:Range):void{
            m_frameRange = _arg1.clone();
            m_frameRange.location = Math.max(1, m_frameRange.location);
            m_frameRange.length = ((Math.min(totalFrames(), ((m_frameRange.location + m_frameRange.length) - 1)) - m_frameRange.location) + 1);
            if (isExecuting()){
                applyFrameRange();
            };
        }
        public function setTarget(_arg1:MovieClip):void{
            m_target = _arg1;
            if (m_frameRange == null){
                m_frameRange = new Range(1, _arg1.totalFrames);
            };
        }
        public function gotoAndStop(_arg1:int):void{
            _arg1 = normalizedFrame(_arg1);
            m_target.gotoAndStop(_arg1);
        }
        public function frameRange():Range{
            return (m_frameRange.clone());
        }
        public function setFrameDelay(_arg1:int):void{
            m_frameDelay = Math.max(0, _arg1);
        }
        protected function applyFrameRange():void{
            if (currentFrame() < m_frameRange.location){
                this.gotoAndStop(m_frameRange.location);
            } else {
                if (currentFrame() > ((m_frameRange.location + m_frameRange.length) - 1)){
                    this.gotoAndStop(((m_frameRange.location + m_frameRange.length) - 1));
                };
            };
        }
        override protected function notifyComplete(_arg1:Boolean):void{
            m_target.removeEventListener(Event.ENTER_FRAME, enterFrame);
            super.notifyComplete(_arg1);
        }
        public function setResetsOnExecute(_arg1:Boolean):void{
            m_resetOnExecute = _arg1;
        }
        public function currentFrame():int{
            return (m_target.currentFrame);
        }
        override public function execute(... _args):void{
            super.execute();
            if (m_resetOnExecute){
                if (m_direction == DIRECTION_FORWARDS){
                    gotoAndStop(m_frameRange.location);
                } else {
                    gotoAndStop(((m_frameRange.location + m_frameRange.length) - 1));
                };
            } else {
                applyFrameRange();
            };
            m_target.addEventListener(Event.ENTER_FRAME, enterFrame);
        }
        protected function normalizedFrame(_arg1:int):int{
            _arg1 = Math.max(_arg1, m_frameRange.location);
            _arg1 = Math.min(_arg1, ((m_frameRange.location + m_frameRange.length) - 1));
            return (_arg1);
        }
        public function resetsOnExecute():Boolean{
            return (m_resetOnExecute);
        }
        override public function cancel():void{
            m_target.removeEventListener(Event.ENTER_FRAME, enterFrame);
            super.cancel();
        }
        public function setDirection(_arg1:int):void{
            m_direction = _arg1;
        }

    }
}//package reprise.commands 
